<?php
class ORMMyOrder extends ORMBase {
  public function __construct() {
    parent::__construct('MyOrder');
  }

  public function __toEpObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMMyOrderCancel.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrderPackage.class.php';
    require_once dirname(__FILE__) . '/ORMPayment.class.php';
    require_once dirname(__FILE__) . '/ORMPurchaseItem.class.php';
    $epObject->trackId = isset($object->trackId) ? $object->trackId : '';
    $epObject->createdDate = (isset($object->createdDate) && $object->createdDate) ? SimpleDate::toStamp($object->createdDate) : 0;
    if (isset($object->disposal) && $object->disposal) {
        $epObject->disposal = $this->__getEpObject_4_lvl_1_object($myManager, $object->disposal, new ORMMyOrderCancel(), 'MyOrderCancel');
    } else {
      if (isset($epObject->disposal)) {
        $myManager->delete($epObject->disposal);
      }
    }
    $epObject->flag = isset($object->flag) ? $object->flag : '';
    $epObject->type = isset($object->type) ? $object->type : '';
    $epObject->date = (isset($object->date) && $object->date) ? SimpleDate::toStamp($object->date) : 0;
    $epObject->price = isset($object->price) ? $object->price : 0;
    if (isset($object->photo) && $object->photo) {
        $epObject->photo = $this->__getEpObject_4_lvl_1_object($myManager, $object->photo, new ORMMyOrderPackage(), 'MyOrderPackage');
    } else {
      if (isset($epObject->photo)) {
        $myManager->delete($epObject->photo);
      }
    }
    if (isset($object->video) && $object->video) {
        $epObject->video = $this->__getEpObject_4_lvl_1_object($myManager, $object->video, new ORMMyOrderPackage(), 'MyOrderPackage');
    } else {
      if (isset($epObject->video)) {
        $myManager->delete($epObject->video);
      }
    }
    $epObject->note = isset($object->note) ? $object->note : '';
    if (isset($epObject->purchaseItems)) {
      $epObject->purchaseItems->removeAll();
      foreach ($object->purchaseItems as &$item) {
        $epObject->purchaseItems[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMPurchaseItem(), 'PurchaseItem');
      }
    }
    if (isset($epObject->payments)) {
      $epObject->payments->removeAll();
      foreach ($object->payments as &$item) {
        $epObject->payments[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMPayment(), 'Payment');
      }
    }
    $epObject->customerId = isset($object->customerId) ? $object->customerId : 0;
    $epObject->finished = isset($object->finished) ? $object->finished : 0;
    $epObject->discount = isset($object->discount) ? $object->discount : 0;
    $epObject->isOrderDiscountSolved = isset($object->isOrderDiscountSolved) ? $object->isOrderDiscountSolved : 0;
    $epObject->isNoWeddingDaySolved = isset($object->isNoWeddingDaySolved) ? $object->isNoWeddingDaySolved : 0;
    $epObject->isPayment1FirstSolved = isset($object->isPayment1FirstSolved) ? $object->isPayment1FirstSolved : 0;
    $epObject->isPayment1SecondSolved = isset($object->isPayment1SecondSolved) ? $object->isPayment1SecondSolved : 0;
    $epObject->isPayment1ThirdSolved = isset($object->isPayment1ThirdSolved) ? $object->isPayment1ThirdSolved : 0;
    $epObject->isPayment1ForthSolved = isset($object->isPayment1ForthSolved) ? $object->isPayment1ForthSolved : 0;
    $epObject->isPayment2FirstSolved = isset($object->isPayment2FirstSolved) ? $object->isPayment2FirstSolved : 0;
    $epObject->isPayment2SecondSolved = isset($object->isPayment2SecondSolved) ? $object->isPayment2SecondSolved : 0;
    $epObject->isPayment3FirstSolved = isset($object->isPayment3FirstSolved) ? $object->isPayment3FirstSolved : 0;
    $epObject->isPayment3SecondSolved = isset($object->isPayment3SecondSolved) ? $object->isPayment3SecondSolved : 0;
    $epObject->isPayment4Solved = isset($object->isPayment4Solved) ? $object->isPayment4Solved : 0;
    $epObject->isBonusPaid = isset($object->isBonusPaid) ? $object->isBonusPaid : 0;
    $epObject->admAppr = isset($object->admAppr) ? $object->admAppr : 0;
    $epObject->discAdmAppr = isset($object->discAdmAppr) ? $object->discAdmAppr : 0;
    return $epObject;
  }

  public function __toObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMMyOrderCancel.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrderPackage.class.php';
    require_once dirname(__FILE__) . '/ORMPayment.class.php';
    require_once dirname(__FILE__) . '/ORMPurchaseItem.class.php';
    $object->id = $epObject->oid;
    $object->trackId = $epObject->trackId;
    $object->createdDate = ($epObject->createdDate != 0) ? SimpleDate::fromStamp($epObject->createdDate) : 0;
    if (isset($epObject->disposal)) {
      $object->disposal = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->disposal, new ORMMyOrderCancel());
    }
    $object->flag = $epObject->flag;
    $object->type = $epObject->type;
    $object->date = ($epObject->date != 0) ? SimpleDate::fromStamp($epObject->date) : 0;
    $object->price = $epObject->price;
    if (isset($epObject->photo)) {
      $object->photo = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->photo, new ORMMyOrderPackage());
    }
    if (isset($epObject->video)) {
      $object->video = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->video, new ORMMyOrderPackage());
    }
    $object->note = $epObject->note;
    $object->purchaseItems = array();
    if (isset($epObject->purchaseItems)) {
      foreach ($epObject->purchaseItems as &$item) {
        $object->purchaseItems[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMPurchaseItem());
      }
    }
    $object->payments = array();
    if (isset($epObject->payments)) {
      foreach ($epObject->payments as &$item) {
        $object->payments[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMPayment());
      }
    }
    $object->customerId = $epObject->customerId;
    $object->finished = $epObject->finished;
    $object->discount = $epObject->discount;
    $object->isOrderDiscountSolved = $epObject->isOrderDiscountSolved;
    $object->isNoWeddingDaySolved = $epObject->isNoWeddingDaySolved;
    $object->isPayment1FirstSolved = $epObject->isPayment1FirstSolved;
    $object->isPayment1SecondSolved = $epObject->isPayment1SecondSolved;
    $object->isPayment1ThirdSolved = $epObject->isPayment1ThirdSolved;
    $object->isPayment1ForthSolved = $epObject->isPayment1ForthSolved;
    $object->isPayment2FirstSolved = $epObject->isPayment2FirstSolved;
    $object->isPayment2SecondSolved = $epObject->isPayment2SecondSolved;
    $object->isPayment3FirstSolved = $epObject->isPayment3FirstSolved;
    $object->isPayment3SecondSolved = $epObject->isPayment3SecondSolved;
    $object->isPayment4Solved = $epObject->isPayment4Solved;
    $object->isBonusPaid = $epObject->isBonusPaid;
    $object->admAppr = $epObject->admAppr;
    $object->discAdmAppr = $epObject->discAdmAppr;
    return $object;
  }
}
?>
